<template>
  <div class="app-container calendar-list-container">
    <!-- filter 条件查询 -->
    <div class="filter-container">设备编辑：{{this.equipmentNumber}}</div>
    <!--表格 -->
    <el-table
      :data="list"
      element-loading-text="给我一点时间"
      v-loading="loading.list"
      border
      fit
      highlight-current-row
      style="width: 100%"
    >
      <el-table-column  type="index"  label="序号" align="center" width="80px"/>
      <el-table-column prop="equipmentNumber" label="设备号" align="center"/>
      <el-table-column prop="ctime" label="时间" align="center"/>
      <el-table-column prop="electricQuantity" label="用电量(度)" align="center"/>
    </el-table>
    <!-- pagination 分页 -->
    <div class="pagination-container">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="listQuery.offset"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="listQuery.limit"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </div>
    <!-- 回到顶部 -->
    <BackToTop></BackToTop>
  </div>
</template>
<script>
import { getEquipmentMouthList } from "@/api/equipment";
import { getElectricQuantityList, getBackMonthList } from "@/api/equipmentEle";
import BackToTop from "@/components/BackToTop";
export default {
  name: "equipmentEleDate",
  components: {
    BackToTop
  },
  data() {
    return {
      loading: {
        list: false
      },
      dialog: {
        view: false
      },
      equipmentNumber: this.$route.query.equipmentNumber,
      total: 0,
      listQuery: {
        offset: 1,
        limit: 10,
        equipmentId: this.$route.query.equipmentId
      },
      list: null,
      downloadLoading: false
    };
  },

  methods: {
      //  获取每个月电量
    async getBackMonthLists(){
    
        this.loading.list = true;
      try {
         const {data} =await getBackMonthList({...this.listQuery})
        //  console.log(data)
        this.list = data.records;
        this.total = data.total;
      } catch (error) {}
      this.loading.list = false;


    },

    //导出
    handleDownload() {
      this.downloadLoading = true;
      import("@/vendor/Export2Excel").then(excel => {
        const tHeader = [
          "用户昵称",
          "用户类型",
          "设备编号",
          "设备电量",
          "操作状态",
          "操作时间"
        ];
        const filterVal = [
          "nickName",
          "userKind",
          "equipmentNumber",
          "cellVoltage",
          "lockState",
          "cTime"
        ];
        const data = this.formatJson(filterVal, this.list);
        excel.export_json_to_excel({
          header: tHeader,
          data,
          filename: "开关锁列表"
        });
        this.downloadLoading = false;
      });
    },
    formatJson(filterVal, jsonData) {
      return jsonData.map(v =>
        filterVal.map(j => {
          if (j === "cellVoltage") {
            if (v[j]) {
              return v[j] ? v[j] + "%" : "0%";
            }
          } else if (j === "userKind") {
            if (v[j]) {
              return v[j] === 1 ? "普通用户" : "后勤人员";
            }
          } else if (j === "lockState") {
            if (v[j]) {
              return v[j] === 1 ? "开锁" : "关锁";
            }
          } else {
            return v[j];
          }
        })
      );
    },
    //获取列表
    // async getList() {
    //   this.loading.list = true;
    //   try {
    //     const { data } = await getEquipmentMouthList({
    //       ...this.listQuery
    //     });
    //     this.list = data.records.map((item, index) => ({
    //       index: index + 1,
    //       isFlowInfo: item.isFlow == 1 ? "交流" : "直流",
    //       isUseInfo: item.isFlow == 1 ? "空闲" : "使用中",
    //       ...item
    //     }));
    //     this.total = data.total;
    //   } catch (error) {}
    //   this.loading.list = false;
    // },
    //点击查找
    handleFilter() {
      this.listQuery.offset = 1;
      this.getList();
    },
    handleSizeChange(val) {
      this.listQuery.limit = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.listQuery.offset = val;
      this.getList();
    }
  },

  created() {
    // this.getList();
    this.getBackMonthLists()
  }
};
</script>
<style lang="scss" scoped>
/deep/ .el-carousel__container {
  height: 500px !important;
}
</style>
